//
//  Tool.m
//  YouinRTCDemo
//
//  Created by 潘欣 on 2023/6/23.
//

#import "Tool.h"

@implementation Tool
+(BOOL)strIsNULL:(NSString *)str
{
    if ([str isEqualToString:@""]||str.length==0||[[str stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]]length]==0||[str isEqualToString:@"0"]) {
        return YES;
    }else{
        return NO;
    }
}

// 删除美颜参数
+ (void)resetAllBeautifySettings {
//    NSArray *beautifyKeys = @[
//        @"BeautifyLighteningLevel",
//        @"BeautifyRednessLevel",
//        @"BeautifySharpnessLevel",
//        @"BeautifySmoothnessLevel",
//        @"beautySwitchButton",
//        @"makeUpBeautySwitchButton",
//        @"browStyle",
//        @"lashStyle",
//        @"shadowStyle",
//        @"pupilStyle",
//        @"blushStyle",
//        @"blushColor",
//        @"lipStyle",
//        @"lipColor",
//        @"browStrength",
//        @"lashStrength",
//        @"shadowStrength",
//        @"pupilStrength",
//        @"blushStrength",
//        @"lipStrength",
//        @"browColor",
//        @"lashColor",
//    ];

    
    NSArray *beautifyKeys = @[FUPersistentBeautySkinKey,FUPersistentBeautySkinSegmentationKey,FUPersistentBeautyShapeKey,FUPersistentBeautyFilterKey,FUPersistentBeautySelectedFilterIndexKey];
    
    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
    for (NSString *key in beautifyKeys) {
        [defaults removeObjectForKey:key];
    }
    [defaults synchronize];
}

+ (NSInteger)safeIntForKey:(NSString *)key defaultValue:(NSInteger)defaultValue {
    id obj = [[NSUserDefaults standardUserDefaults] objectForKey:key];
    if (obj == nil) {
            return defaultValue;  // 当key不存在时返回传入的默认值
        }
    return [obj integerValue];
}

+ (float)safeFloatForKey:(NSString *)key defaultValue:(float)defaultValue {
    id obj = [[NSUserDefaults standardUserDefaults] objectForKey:key];
    if (obj == nil) {
            return defaultValue;  // 当key不存在时返回传入的默认值
        }
    return [obj floatValue];
}

+ (BOOL)checkIfUserDefaultsChanged {
    // 定义默认值字典
    NSDictionary *defaultValues = @{
        @"BeautifyLighteningLevel": @0.5,
        @"BeautifyRednessLevel": @0.5,
        @"BeautifySharpnessLevel": @0.5,
        @"BeautifySmoothnessLevel": @0.5,
        @"beautySwitchButton": @YES,
        @"makeUpBeautySwitchButton": @NO,
        @"browStyle": @0,
        @"lashStyle": @0,
        @"shadowStyle": @0,
        @"pupilStyle": @0,
        @"blushStyle": @0,
        @"blushColor": @0,
        @"lipStyle": @0,
        @"lipColor": @0,
        @"browStrength":@0.5,
        @"lashStrength":@0.5,
        @"shadowStrength":@0.5,
        @"pupilStrength":@0.5,
        @"blushStrength":@0.5,
        @"lipStrength":@0.5,
        @"lashColor":@0,
        @"browColor":@0,
    };
    
    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
    BOOL hasChanged = NO;
    
    // 检查所有键值
    for (NSString *key in defaultValues.allKeys) {
        id currentValue = [defaults objectForKey:key];
        id defaultValue = defaultValues[key];
        
        // 如果当前值与默认值不同
        if (currentValue && ![currentValue isEqual:defaultValue]) {
            NSLog(@"键 %@ 已修改 - 当前值: %@, 默认值: %@", key, currentValue, defaultValue);
            hasChanged = YES;
        }
    }
    
    return hasChanged;
}

//+(NSString *)getMakeupResource {
//    NSString *bundlePath = [[NSBundle mainBundle] pathForResource:@"vv_make_up" ofType:@"bundle"];
//    NSLog(@"Bundle路径: %@", bundlePath ?: @"未找到bundle");
//    
//    if (!bundlePath || ![[NSBundle alloc] initWithPath:bundlePath]) {
//        NSLog(@"Bundle加载失败");
//        return @"";
//    }
//    
//    NSString *path = [bundlePath stringByAppendingPathComponent:@"vv_make_up"];
//    return path;
//}

+ (BOOL)is24HourFormat {
    NSLocale *locale = [NSLocale currentLocale];
      NSString *dateFormat = [NSDateFormatter dateFormatFromTemplate:@"j" options:0 locale:locale];
      // 如果 "j" 包含 "a"（AM/PM），说明是 12 小时制
      return [dateFormat rangeOfString:@"a"].location == NSNotFound;
}
@end
